package com.example.springbootemail.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author jie
 * @date 2019/3/22 0022 -15:29
 */
@Service
public class MainService {

    @Value("${spring.mail.username}")
    private String from;

    @Resource
    private JavaMailSender mailSender;

    public void sayHello(){
        System.out.println("Hello World");
    }

    public void sendSimpleMail(String to,String suject,String content){
        SimpleMailMessage message = new SimpleMailMessage();
        message.setTo(to);
        message.setSubject(suject);
        message.setText(content);
        message.setFrom(from);

        mailSender.send(message);
    }

}
